package com.zealcomm.ivcscustomer.adapter

import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.zealcomm.annotations.ChatRoleType
import com.zealcomm.commonui.beans.MessageContent
import com.zealcomm.ivcscustomer.databinding.ItemRobotMessageBinding

class RobotMessageAdapter(robotMessages: MutableList<MessageContent>) :
    RecyclerView.Adapter<RobotMessageAdapter.MyViewHolder>() {
    private val orange = Color.parseColor("#ff7845")
    private val blue = Color.parseColor("#98daff")
    private var data = robotMessages

    class MyViewHolder(binding: ItemRobotMessageBinding) :
        RecyclerView.ViewHolder(binding.root) {
        var binding = binding
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        return MyViewHolder(
            ItemRobotMessageBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        if (data[position].role == ChatRoleType.AGENT) {
            holder.binding.tvRole.text = "客服："
            holder.binding.tvRole.setTextColor(orange)
        } else {
            holder.binding.tvRole.text = "访客："
            holder.binding.tvRole.setTextColor(blue)
        }
        holder.binding.tvMessage.text = data[position].messageContent.data.toString()
    }

    override fun getItemCount(): Int {
        return data.size
    }
}